/* 
 * File:   Sqr.cpp
 * Author: Gab'z
 * 
 * Created on 4 juin 2012, 09:40
 */

#include "Sqr.h"
#include "../../../Context.h"
#include "../../literal/Stack.h"

namespace calculator {

    Sqr::Sqr(const std::string name) : UnaryOperator(name) {
    }

    Sqr::Sqr(const Sqr& orig) : UnaryOperator(orig._name) {
    }

    Sqr::~Sqr() {
    }

    std::string Sqr::isExecutable() const {
        if (Context::getInstance()->getCurrentStack()->size() == 0) return "Empty stack";
        return "";
    }

    Sqr* Sqr::clone() const {
        return new Sqr(_name);
    }

    const Number* Sqr::apply(const Number* number) const throw (ArithmeticException) {
        const Number* n;
        try {
            n = mul(number, number);
        } catch (ArithmeticException& e) {
            throw;
        }
        return n;
    }
}